package com.yds.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * 创建者：于德水
 * 创建时间：2022/1/13 0013 10:48
 * 创建描述：控制viewpager是否滑动
 */
public class YDSScrollControlViewPager extends ViewPager {
	private boolean scroll = true;                     //false 禁止viewpager左右滑动

	public YDSScrollControlViewPager(Context context) {
		super(context);
	}

	public YDSScrollControlViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/*设置是否允许滑动*/
	public void setScroll(boolean scroll) {
		this.scroll = scroll;
	}

	@Override
	public void scrollTo(int x, int y) {
		super.scrollTo(x, y);
	}

	@Override
	public boolean onTouchEvent(MotionEvent arg0) {
		if (!scroll)
			return false;
		else
			return super.onTouchEvent(arg0);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		if (!scroll)
			return false;
		else
			return super.onInterceptTouchEvent(arg0);
	}

	@Override
	public void setCurrentItem(int item, boolean smoothScroll) {
		super.setCurrentItem(item, smoothScroll);
	}

	@Override
	public void setCurrentItem(int item) {
		super.setCurrentItem(item);
	}

}
